import { Engine } from '../engine';
import { Util } from '../../utils/util';

export class CommodityFilter {
    constructor({ storeId = null, wareHouse = null } = {}) {
        this.name = null;
        this.code = null;
        this.qrCode = null;
        this.categoryId = null;
        this.categoryName = null;
        this.mixedLikeInfo = null;
        this.stateFilter = true;
        this.storeId = storeId || (Engine.profile?.filterStore?.id ?? null);
        this.zeroInventoryFilter = null;
        this.wareHouse = wareHouse;
    }

    clear() {
        this.name = null;
        this.code = null;
        this.qrCode = null;
        this.categoryId = null;
        this.categoryName = null;
        this.stateFilter = true;
        this.zeroInventoryFilter = null;
        // this.wareHouse = null;
    }

    static clone(filter) {
        const clone = new CommodityFilter({ storeId: filter.storeId, wareHouse: filter.wareHouse });
        clone.name = filter.name;
        clone.code = filter.code;
        clone.qrCode = filter.qrCode;
        clone.categoryId = filter.categoryId;
        clone.categoryName = filter.categoryName;
        clone.stateFilter = filter.stateFilter;
        clone.zeroInventoryFilter = filter.zeroInventoryFilter;
        return clone;
    }

    toJson({ mergeFilter = {} } = {}) {
        const ret = { ...mergeFilter };
        if (this.name) ret['lke_commodityName'] = this.name;
        if (this.code) ret['lke_commodityCode'] = this.code;
        if (this.qrCode) ret['lke_commodityBarcode'] = this.qrCode;
        if (this.categoryId) ret['commodityCategoryId'] = this.categoryId;
        if (this.stateFilter != null) ret['useState'] = this.stateFilter ? 1 : 2;
        if (this.storeId) ret['ign_storeId'] = this.storeId;
        if (this.mixedLikeInfo) ret['ign_mixedLikeInfo'] = this.mixedLikeInfo;
        if (this.zeroInventoryFilter) ret['ign_filterZeroCount'] = 1;
        if (this.wareHouse) ret['ign_storageId'] = this.wareHouse.id;
        return ret;
    }
}
